// Fill out your copyright notice in the Description page of Project Settings.

#pragma once

//#undef check
#include <opencv2/core.hpp>
#include <opencv2/highgui.hpp>
#include "CoreMinimal.h"
#include "GameFramework/Actor.h"
#include "WebcamUpdater.generated.h"

UCLASS()
class EXAMPLE09_UE4_API AWebcamUpdater : public AActor
{
	GENERATED_BODY()
	
public:
	AWebcamUpdater();

	UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = Webcam)
	int32 _cameraID;

	UPROPERTY(BlueprintReadOnly, Category = Webcam)
	bool _isOpen;

	UPROPERTY(BlueprintReadOnly, Category = Webcam)
	FVector2D _videoSize;

	UPROPERTY(BlueprintReadOnly, Category = Webcam)
	UTexture2D* _videoTexture;

protected:
	virtual void BeginPlay() override;

	void UpdateTextureData();

	FUpdateTextureRegion2D* _region;
	TArray<FColor> _data;
	cv::VideoCapture _capturer;
	cv::Mat _frame;

public:
	virtual void Tick(float DeltaTime) override;
};
